using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.Framework;
using System.IO;

namespace BizTalk.BuildGenerator.Tasks.BAM
{
    /// <summary>
    /// This will back up all BAM definitions to a temporary location and then use the definition temp file to remove all artefacts from BAM
    /// The bam instance can be restored from this temp location
    /// </summary>
    public class CleanBam : BaseBMTask
    {        
        private string _TempDefinitionFilePath;

        /// <summary>
        /// The path to the temp definition file
        /// </summary>
        [Required]
        public string TempDefinitionFilePath
        {
            get { return _TempDefinitionFilePath; }
            set { _TempDefinitionFilePath = value; }
        }        
        /// <summary>
        /// Executes the task
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            const string BackUpArgsFormat = "get-defxml -FileName:{0}";
            base.ExecuteBM(string.Format(BackUpArgsFormat, this._TempDefinitionFilePath));

            Logger.LogMessage(this, "All current definitions have been backed up to the following location: " + this._TempDefinitionFilePath);

            const string RemoveArgsFormat = "remove-all -DefinitionFile:{0}";
            return base.ExecuteBM(string.Format(RemoveArgsFormat, this._TempDefinitionFilePath));            
        }
    }
}
